package com.easy.work.function.city.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.easy.work.R;
import com.easy.work.function.mall.bean.JobCommonBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/1/7.
 * 城市
 */
public class ProvinceAdapter extends BaseAdapter {

    private Context mCtx;
    private List<JobCommonBean.ItemsEntity> listmain;

    public ProvinceAdapter(Context context, List<JobCommonBean.ItemsEntity> listmain) {
        this.mCtx = context;
        this.listmain = listmain;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listmain.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return listmain.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_pro,
                    null);
            holder = new ViewHolder();
            holder.code = (TextView) convertView.findViewById(R.id.dq_id);
            holder.name = (TextView) convertView.findViewById(R.id.dq_mc);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.code.setText(listmain.get(position).key);
        holder.name.setText(listmain.get(position).text);

        if (position == selectItem) {
            convertView.setBackgroundColor(mCtx.getResources().getColor(R.color.white));
        } else {
            if (position == 0 && selectItem == -1) {
                convertView.setBackgroundColor(mCtx.getResources().getColor(R.color.white));
            } else {
                convertView.setBackgroundColor(mCtx.getResources().getColor(R.color.backgroundMYD));
            }
        }
        return convertView;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    private int selectItem = -1;


    class ViewHolder {
        private TextView code;
        private TextView name;
    }
}